package com.mypg;

import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.FrameGrabber;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class VideoHelper {
    private int video_id;
    private String video_title;
    private String video_img;
    private String video_content;
    private String video_class;
    private String video_class_sub;
    private String video_length;


    public static VideoHelper changeVideoToVideoHelper(Video video){
        VideoHelper videoHelper=new VideoHelper();
        videoHelper.setVideo_id(video.getVideo_id());
        videoHelper.setVideo_title(video.getVideo_title());
        videoHelper.setVideo_img(video.getVideo_img());
        videoHelper.setVideo_content(video.getVideo_content());
        videoHelper.setVideo_class(video.getVideo_class());
        videoHelper.setVideo_class_sub(video.getVideo_class_sub());

        String path="E:\\毕设有关\\上传的文件\\图片\\video_file\\";
        path+=video.getVideo_content();
        File file_video=new File(path);
        long duration = 0L;
        FFmpegFrameGrabber ff = new FFmpegFrameGrabber(file_video);
        try {
            ff.start();
            duration = ff.getLengthInTime() / (1000 * 1000);
            ff.stop();
        } catch (FrameGrabber.Exception e) {
            e.printStackTrace();
        }
        String res="";
        int mm= (int) Math.floor(duration/60);
        int ss= (int) (duration-(mm*60));
        res=mm+":"+ss;
        videoHelper.setVideo_length(res);
        return videoHelper;
    }

    public static List<VideoHelper> changeVideoListToVideoHelperList(List<Video> videoList){
        List<VideoHelper> videoHelperList=new ArrayList<>();
        for(int i=0;i<videoList.size();i++){
            videoHelperList.add(VideoHelper.changeVideoToVideoHelper(videoList.get(i)));
        }
        return videoHelperList;
    }




    public VideoHelper() {
    }
    public VideoHelper(int video_id, String video_title, String video_img, String video_content, String video_class, String video_class_sub, String video_length) {
        this.video_id = video_id;
        this.video_title = video_title;
        this.video_img = video_img;
        this.video_content = video_content;
        this.video_class = video_class;
        this.video_class_sub = video_class_sub;
        this.video_length = video_length;
    }

    public int getVideo_id() {
        return video_id;
    }

    public void setVideo_id(int video_id) {
        this.video_id = video_id;
    }

    public String getVideo_title() {
        return video_title;
    }

    public void setVideo_title(String video_title) {
        this.video_title = video_title;
    }

    public String getVideo_img() {
        return video_img;
    }

    public void setVideo_img(String video_img) {
        this.video_img = video_img;
    }

    public String getVideo_content() {
        return video_content;
    }

    public void setVideo_content(String video_content) {
        this.video_content = video_content;
    }

    public String getVideo_class() {
        return video_class;
    }

    public void setVideo_class(String video_class) {
        this.video_class = video_class;
    }

    public String getVideo_class_sub() {
        return video_class_sub;
    }

    public void setVideo_class_sub(String video_class_sub) {
        this.video_class_sub = video_class_sub;
    }

    public String getVideo_length() {
        return video_length;
    }

    public void setVideo_length(String video_length) {
        this.video_length = video_length;
    }

    @Override
    public String toString() {
        return "VideoHelper{" +
                "video_id=" + video_id +
                ", video_title='" + video_title + '\'' +
                ", video_img='" + video_img + '\'' +
                ", video_content='" + video_content + '\'' +
                ", video_class='" + video_class + '\'' +
                ", video_class_sub='" + video_class_sub + '\'' +
                ", video_length='" + video_length + '\'' +
                '}';
    }
}
